package com.example.mine_platform.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.example.mine_platform.mapper.CheckClockMapper;
import com.example.mine_platform.pojo.dto.CheckClockDTO;
import com.example.mine_platform.pojo.entities.CheckClock;
import com.example.mine_platform.pojo.entities.User;
import com.example.mine_platform.service.CheckClockService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@Service
@Slf4j
public class CheckClockServiceImpl implements CheckClockService {
    @Resource
    CheckClockMapper checkClockMapper;
    @Override
    public void add(CheckClock checkClock){
        checkClockMapper.insertSelective(checkClock);
    }
    @Override
    public PageInfo<CheckClock> findBySearch(Integer userId, Integer pageSize, Integer pageNum){
        log.info("userId:{},pageSize:{},pageNum:{}",userId,pageSize,pageNum);
        PageHelper.startPage(pageNum, pageSize);
        //接下来的查询会自动开启分页查询
         CheckClock checkClock=CheckClock.builder().userId(userId).build();
        List<CheckClock> checkClockList = checkClockMapper.select(checkClock);
        if(ObjectUtil.isEmpty(checkClockList)){
            return PageInfo.of(new ArrayList<>());
        }
        return PageInfo.of(checkClockList);
    }
    @Override
    public PageInfo<CheckClockDTO> findBySearch(String userName, Integer pageSize, Integer pageNum){
        log.info("userId:{},pageSize:{},pageNum:{}",userName,pageSize,pageNum);
        PageHelper.startPage(pageNum, pageSize);
        //接下来的查询会自动开启分页查询

        List<CheckClockDTO> checkClockList = checkClockMapper.selectwithUser(userName);
        if(ObjectUtil.isEmpty(checkClockList)){
            return PageInfo.of(new ArrayList<>());
        }
        return PageInfo.of(checkClockList);
    }

}
